/*
 * @Author: thl t15945324431@163.com
 * @Date: 2024-05-07 10:15:01
 * @LastEditors: thl t15945324431@163.com
 * @LastEditTime: 2024-05-08 15:27:38
 * @FilePath: \cw_web\gl\src\views\wallet\setting\depositSettings\component\alllimit.jsx
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import React, { Component } from "react"
import { Input, Form, InputNumber, Modal, Space } from 'antd';
import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons';
import TheButton from '@/components/TheButton';
import { rechargeWithdrawList, rechargeWithdrawEdit } from '@/request/wallet/rechargeWithdraw'
import EditInput from "./editInput";

export default class allLimit extends Component {
    constructor() {
        super()
        this.state = {
            visible: false,
        }
    }
    componentDidMount() {
        // this.getData()
    }
    control = (visible) => {
        this.setState({
            visible
        })
    }
    onFinish = (value) => {
        if (value.users.length == 0) return React.$message({
            type: 'error',
            content: '请至少添加一条'
        })
        const flag = value.users.every(item => item.startDay <= item.endDay)
        if (!flag) return React.$message({
            type: 'error',
            content: '结束时间需大于或等于开始时间'
        })
        this.props.save(value.users)
    }

    render() {
        const { visible } = this.state
        const { title, arr, tips } = this.props
        return (
            <div>
                <Modal
                    open={visible}
                    title={tips}
                    footer={null}
                    width='85vw'
                    onCancel={() => this.control(false)}
                >
                    <Form onFinish={this.onFinish} initialValues={{
                        users: arr
                    }} autoComplete="off" >
                        <Form.List name="users">
                            {(fields, { add, remove }) => (
                                <>
                                    {fields.map(({ key, name }, index) => (
                                        <Space
                                            key={key}
                                            style={{
                                                display: 'flex',
                                                marginBottom: 8,
                                            }}
                                            align="baseline"
                                        >
                                            {index + 1}
                                            新人注册,第
                                            <Form.Item
                                                style={{ width: "100px" }}
                                                name={[name, 'startDay']}
                                                rules={[
                                                    {
                                                        required: true,
                                                        message: '此项为必填项',
                                                    },
                                                ]}
                                            >
                                                <InputNumber placeholder="开始时间" max={300} precision={0} />
                                            </Form.Item>
                                            -
                                            <Form.Item
                                                style={{ width: "100px" }}
                                                name={[name, 'endDay']}
                                                rules={[
                                                    {
                                                        required: true,
                                                        message: '此项为必填项',
                                                    },
                                                ]}
                                            >
                                                <InputNumber placeholder="结束时间" max={300} min={1} precision={0} />
                                            </Form.Item>
                                            天,{title}为
                                            <Form.Item
                                                style={{ width: "150px" }}
                                                name={[name, 'amountPerDay']}
                                                rules={[
                                                    {
                                                        required: true,
                                                        message: '此项为必填项',
                                                    },
                                                ]}
                                            >
                                                <InputNumber max={9999999} min={0} precision={0} />
                                            </Form.Item>
                                            元，超出后提示文案为
                                            <Form.Item
                                                name={[name, 'noticeMessage']}
                                                rules={[
                                                    {
                                                        required: true,
                                                        message: '此项为必填项',
                                                    },
                                                    {
                                                        pattern: /^[^\s]*$/,
                                                        message: '禁止输入空格',
                                                    },
                                                ]}
                                                getValueFromEvent={(e) => e.target.value.replace(/(^\s*)|(\s*$)/g, '')}
                                            >
                                                <Input placeholder="提示文案" maxLength={30} showCount style={{ width: '500px' }} />
                                            </Form.Item>
                                            {index != 0 && <MinusCircleOutlined onClick={() => remove(name)} />}
                                        </Space>
                                    ))}
                                    <Form.Item>
                                        {fields.length < 5 && <TheButton type="dashed" onClick={() => add()} block icon={<PlusOutlined />} style={{ height: '50px' }}>
                                            新增
                                        </TheButton>}
                                    </Form.Item>
                                </>
                            )}
                        </Form.List>
                        <Form.Item>
                            <Space align="center" style={{ display: 'flex', justifyContent: 'center' }}>
                                <TheButton size="middle" type="dashed" onClick={() => this.control(false)}>
                                    取消
                                </TheButton>
                                <TheButton size="middle" type="primary" htmlType="submit">
                                    保存
                                </TheButton>
                            </Space>
                        </Form.Item>
                    </Form>
                </Modal>
            </div>
        )
    }
}